import openpyxl
import os
import random

# 假设是高一年级,高一年级有20个班
class_name = "高一"
class_number = 20
# 创建高一年级的文件夹
if not os.path.exists(class_name):
    os.makedirs(class_name)


# 创建Excel,生成模拟数据
def mk_excel(excel_name):
    wb = openpyxl.Workbook()
    ws = wb.active
    # 追加一行数据
    ws.append(['姓名', '年龄', '性别', '语文', '英语', '数学', '政治', '历史', '地理'])

    # 批量追加数据
    for i in range(50):
        ws.append(['学生{}'.format(i),
                   random.randint(15, 18),
                   ['男', '女'][random.randint(0, 1)],
                   random.randint(0, 150),
                   random.randint(0, 150),
                   random.randint(0, 150),
                   random.randint(0, 100),
                   random.randint(0, 100),
                   random.randint(0, 100)
                   ])
    wb.save(excel_name)


# 创建高一年级每个班的模拟数据
for i in range(class_number):
    temp_name = "高一({})班".format(i + 1)
    excel_name = "{}.xlsx".format(temp_name)
    temp_excel_name = "{}/{}".format(class_name, excel_name)
    # 如果有则删除
    if os.path.exists(temp_excel_name):
        os.remove(temp_excel_name)
    # 生成模拟数据
    print(temp_excel_name)
    mk_excel(temp_excel_name)
